package com.febs.security.code.sms;


import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.febs.security.code.ValidateCode;
import com.febs.security.code.ValidateCodeGenerator;
import com.febs.security.properties.FebsSecurityProperties;

/**
 * @author zhongyj <1126834403@qq.com><br/>
 * @date 2021/6/18
 */
@Component("smsCodeGenerator")
public class SmsCodeGenerator implements ValidateCodeGenerator {

    @Resource
    private FebsSecurityProperties securityProperties;

    @Override
    public ValidateCode createCode(HttpServletRequest request, HttpServletResponse response) {
        String code = RandomStringUtils.randomNumeric(securityProperties.getCode().getSms().getLength());
        return new ValidateCode(code, securityProperties.getCode().getSms().getExpireIn());
    }
}
